﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using Library;

namespace BusinessLayer
{
   public class Producer
    {
#region "Variables and Properties"
//Variables
        private int producer_ID;
        private string producer_Name;
        private string producer_Website;
        private int status;

        
//Properties
        public int Producer_ID
        {
            get { return producer_ID; }
            set { producer_ID = value; }
        }
        public string Producer_Name
        {
            get { return producer_Name; }
            set { producer_Name = value; }
        }
        public string Producer_Website
        {
            get { return producer_Website; }
            set { producer_Website = value; }
        }
        public int Status
        {
            get { return status; }
            set { status = value; }
        }
#endregion

#region "Initial Methods"
        public Producer() { }

        public Producer(SqlDataReader sdr)
        {
            if (sdr != null && !sdr.IsClosed)
            {
                producer_ID = sdr.GetInt32(0);
                if (!sdr.IsDBNull(1))
                    producer_Name = sdr.GetString(1);
                if (!sdr.IsDBNull(2))
                    producer_Website = sdr.GetString(2);
                if (!sdr.IsDBNull(3))
                    status = sdr.GetInt32(3);
            }
        }
#endregion

#region "Business Methods"
//Get all Producer
        public static List<Producer> GetAll()
        {
            DBHelp dbh = new DBHelp();
            string cmd = "tbl_Producer_SHOWALL";
            List<Producer> lstProducer = new List<Producer>();
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);
            while (sdr.Read())
            {
                lstProducer.Add(new Producer(sdr));
            }
            return lstProducer;
        }
//Get one Producer
        public static Producer GetOne(int id)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Producer_ID", id);
            string cmd = "tbl_Producer_SHOWONE";
            Producer producer = new Producer();
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);
            if (sdr.Read())
            {
                producer.Producer_ID = sdr.GetInt32(0);
                if (!sdr.IsDBNull(1))
                    producer.Producer_Name = sdr.GetString(1);
                if (!sdr.IsDBNull(2))
                    producer.Producer_Website = sdr.GetString(2);
                if (!sdr.IsDBNull(3))
                    producer.Status = sdr.GetInt32(3);
            }
            return producer;
        }
//Insert a Producer
        public static void Insert(Producer producer)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Producer_Name", producer.producer_Name);
            dbh.AddParameter("@Producer_Website", producer.producer_Website);
            string cmd = "tbl_Producer_INSERT";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }
//Update a Producer
        public static void Update(Producer producer)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Producer_ID", producer.Producer_ID);
            dbh.AddParameter("@Producer_Name", producer.producer_Name);
            dbh.AddParameter("@Producer_Website", producer.producer_Website);
            string cmd = "tbl_Producer_UPDATE";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }
//Delete a Producer
        public static void Delete(int Id)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@Producer_ID", Id);
            string cmd = "tbl_Producer_DELETE";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }
#endregion
    }
}
